Memory control method, storage device, control program, and readable record medium

ABSTRACT

A technique is provided for storing updated values of a data item in a segment of memory in which stored values cannot be individually overwritten, such as a flash memory. Each updated value is stored at an address which has space for a far pointer and a local pointer. When a new value is stored, the local pointer of the previous value is set to point to the address of the new value. When a chain of nodes of this type has been established and a further update value is to be stored, it is entered at a new node and a far pointer at a much earlier node of the chain is set to point to the new node so that the most recent value can be found without having to follow the local pointers in all of the previous nodes.

TECHNICAL FIELD

The present invention relates to: a memory control method for storingtemporally consecutive values to enable reading the latest value; astorage apparatus using the same; a control program which is used forthe method or the apparatus; and a readable recording medium containingthe program.

BACKGROUND ART

Such techniques may be used in systems embedded in, for example, asemiconductor chip, or the like and examples of suitable applications ofthe storage apparatus include: smart cards such as Java Cards™; digitalactive storage or security devices such as smart keys and smart disks;SIMs (Subscriber IdentityModule) and USIMs (Universal SubscriberIdentityModule) for mobile telephones; data logging devices; smalldevices which record user preferences, store settings or record usagesituations; computer systems in vehicles; set-top boxes; and internetrouters.

The term “Persistent Data Item” or “PDI” as used herein is defined to bea data item having associated with it a variable value which changesover time, in particular when updated by an application program, andwhich is required to retain its state between such updates, particularlywhen the application is not running and when power is removedintentionally, when the application is switched off, or accidentally,for example because of a power failure.

Computer programs operate by reading and updating the values ofvariables. For variables in RAM, this presents little difficulty as thevalues can be rewritten as often as necessary and reading and writing ofdata are fast. When the program is not running, its recording state mustbe stored in more persistent memory.

On small computer platforms such as smart cards, there is little RAM andthe persistent memory often takes the form of EEPROM or Flash memory.This persistent memory has the property that, once a bit has beenchanged, it is not changed again until the whole segment is erased. InEEPROM, the segment size may be as small as a single byte (8 bits) andthe persistent memory can be treated essentially as very slow RAM. Inflash memory, the segments have generally large (e.g. 64 KB) memorycapacities for silicon area efficiency and the erase operation is alsoslow. Also, the life of the persistent memory will eventually ends aftersome number of erase cycles (say 100,000 for high quality Flash). Theadvantage of flash memory is that much more memories can be packed intoa given chip area so there is more storage space, but it is harder thanEEPROM, to use efficiently.

Consider a smart card application which keeps a record of the date andtime (obtained from a card reader terminal, perhaps) on each occasionthat it runs various processes and checks the interval between runs.This could be used for a security function, such as increasing an amountof a daily withdrawal limit for a cash card. Every time it runs variousprocesses, it must read the old run date, check the interval and storethe new run date. The run date is therefore a PDI (persistent dataitem). If the run date were stored in the same location each time itchanges, the whole 64K block would first have to be erased because ofthe physical memory limitations and this would take a long time andrapidly wear out the flash memory and make its life short.

Instead, each time the new date is written, it must be stored in a newarea of memory. It is assumed that this program has to share the flashmemory with other programs, so it is not efficient to pre-allocate alarge block of flash memory just for this one application. In otherwords, there may be many PDIs in the system and PDIs might be updated atdifferent rates, depending on the applications running variousprocesses.

A known arrangement as disclosed in “General-Purpose Persistence UsingFlash Memory”, Jonathan T Moore, Michael Hicks, and Scott Nettles;Technical Report MS-CIS-97-3, CIS Dept. University of Pennsylvania,1997, is to manage PDI (persistent data item) as (persistent data item)logs. Each time a PDI is updated, a log entry (update record) is writtenwith the PDI's identity and the new value. To find the current value,the logs must be scanned to find the most recent value. When the blockof the log entries (update record) is full, just the most recent valuesfor each PDI can be copied to a fresh block, and the old block erased;this is called “garbage collection (collecting data recording areaswhich are not required any more for making them usable)”. This solutionis efficient in flash memory space but, in view of the search times,reading values is slow. Some values can be cached (searched) by copyingthem to RAM, but this uses up valuable RAM space and also requires extratime to search the cache. Writing is fast because it just requiresappending a log (update record).

Another known arrangement builds a linked chain of values for each PDIas illustrated in FIG. 8 of the accompanying drawings. The first elementof the chain is at a known address. Each element of the chain stores avalue for the run date record and has a space for a pointer to the nextitem in the chain. The last chain element will have a pointer valueequal to the erased memory pattern (FFFF in hexadecimal in this model or0000 in the complementary model). To read the current update date,reading starts at the beginning of the chain and sequentially followspointers until one is reached with value FFFF. To add a new update date,a new chain element is created with the new value and an empty pointer.The address is then stored over the pointer part of the previouslast-element. When garbage collecting, the last value in the chain iscopied to the new block and used as the start of the new chain.

-   Example: chain representing the value “date2” (with previous values    “date1” and “date0”).-   Address Contents [value, pointer]

0120 [date0, 0236] // initial value = date0 . . . 0236 [date1, 0240] //value after first update = date1 . . . 0240 [date2, FFFF] // value aftersecond update = date2

-   Now add the new value “date3”, and suppose there is free memory at    address 0332:

0120 [date0, 0236] . . . 0236 [date1, 0240] . . . 0240 [date2, 0332] . .. 0332 [date3, FFFF]

The program code to achieve this is simple and compact (here C style isused to explain the algorithm):

newtype element = record {value v, element* next} procedureupdatevalue_chain(element* startaddress, value newvalue)   = {    element* p = startaddress;     element* newp = malloc(sizeof(element)); // space for new element        newp->v = newvalue; // storethe new value in the new element        while (p.next != 0xFFFF) //search for the end of the chain            do {p = p.next}        p.next= newp; // make the previous pointer point to the new element        }

The problem is that, for each read or update, it is necessary to searchthrough the whole chain of values. In a 64K memory segment, it might benecessary to search up to 16,000 entries (2+2 bytes per entry) when thechain is long and this is too slow in time to perform. If there are Nentries, search time is proportional to N and the space required is(d+2) *N bytes, where d is the number of bytes to store a single valueand pointers take two bytes. However, the solution is compact, each 2byte value uses only 4 bytes for storage and, if the data stops beingupdated, at most 2 bytes at the end of the chain are wasted by beingallocated but not used.

In another known arrangement as disclosed in “Data Management in a FlashMemory Based Storage Server”, Mei-ling Chiang, Paul C H Lee andRuei-Chuan Chang; National Chiao-Tung University, Hsinchu, Taiwan,R.O.C. and Academia Sinica, Nankang, Taiwan, R.O.C., the flash memory isdivided into sub-blocks which are managed by the system. Blocks have tobe rewritten (i.e., new values written to a new area of flash memory andthe old block marked in some way as out-of-date) as a whole. This meansthat, if the blocks are too large, then memory is wasted (e.g., using ablock of 32 bytes to store a 2 byte counter). If the blocks are toosmall, then there are too many blocks and the management overhead iswasteful of CPU searching time or RAM space or both.

In yet another known arrangement as disclosed in “Architecture of thePEVM: a High-Performance Orthogonally Persistent Java™”, Brian Lewis,Bernd Mathiske, Neal Gafter; Sun-Microsystems, Inc., 901 San AntonioRoad, Palo Alto, Calif. 94303-4900, USA, the contents of flash memoryare managed as a virtual memory system with copy-on-write. Flash memoryto be updated is copied into RAM and modified. If there is no space forthe incoming block, then an old block is written back into flash. Thiscan result in a whole block being rewritten because just a single bytein it has changed. This system adds a lot of time overhead to eachaccess because lots of memory copying is required of blocks in and outof RAM.

In “Transacted Memory for Smart Cards”, Pieter H Hartel, Michael JButler, Eduard de Jong and Mark Longley; fphh, mjbg@ecs.soton.ac.uk andEduard.deJong@Sun.COM; Technical Report DSSE-TR-2000-9, Aug. 16, 2000;Declarative Systems and Software Engineering Group, Department ofElectronics and Computer Science, University of Southampton, Highfield,Southampton SO17 1BJ, United Kingdom, a small block size is assumed(e.g., 32 bytes) in a smart card memory and we are shown how to buildtransactional objects. In these objects, updates to arbitrarily manydata items are performed as one (atomically) and, if the transaction isaborted for any reason before completion, it returns to its originalstate.

DISCLOSURE OF THE INVENTION

In order to solve the above-described conventional problems, the presentinvention provides: a memory control method in which PDIs can be updatedfast, space allocated for the PDI in advance is not required, and theupdates are sequentially proceeded to fill available space efficiently;a storage apparatus using the same; a control program which is used forthe method or the apparatus; and a readable recording medium containingthe control program.

According to a first aspect of the invention, there is provided a methodas defined in the appended claim 1. According to a second aspect of theinvention, there is provided an apparatus defined in the appended claim19. According to a third aspect of the invention, there is provided acontrol program as defined in the appended claim 38. According to afourth aspect of the invention, there is provided a readable recordingmedium as defined in the appended claim 39. Preferred embodiments of theinvention are defined in the other appended claims.

In other words, a memory control method according to the presentinvention is a memory control method of storing temporally consecutivevalues of at least one data item in a memory segment of a type in whichstored values cannot be individually overwritten, comprising the stepsof: (a) storing sets of the consecutive values at respective addresssections which are allocated temporally consecutively for the or eachdata item; (b) storing a far pointer to the address of at least one ofthe sets of values at an address section allocated before the addressallocated to the set of values immediately preceding the at least oneset; and (c) storing a local pointer to the address allocated to eachset other than the at least one set at the address section allocated tothe set immediately preceding each other set, thereby achieving theabove-described objectives.

Preferably, in a memory control method according to the presentinvention, the memory segment is non-volatile.

Further preferably, in a memory control method according to the presentinvention, the memory segment is erasable only as a whole.

Further preferably, in a memory control method according to the presentinvention, the memory segment comprises at least part of a flash memory.

Further preferably, in a memory control method according to the presentinvention, the at least one set comprises a plurality of sets and theaddress section at which the far pointer of each respective set of theplurality of sets is stored is one which was allocated before the oreach address at which is stored a far pointer to the or each other ofthe plurality of sets previous to the respective one set.

Further preferably, in a memory control method according to the presentinvention, the step (b) comprises storing a pointer to each(A^(B)(C+1)+(A−B)+K)th set at an address section allocated to a(A^(B)C+(A−B)+K)th set, where A is a predetermined integer constantgreater than one, B is an integer parameter greater than zero, C is aninteger parameter which is zero or greater, and K is a predeterminedinteger constant which is zero or greater.

Further preferably, in a memory control method according to the presentinvention, 1≦B≦A and K=0.

Further preferably, in a memory control method according to the presentinvention, A=4.

Further preferably, in a memory control method according to the presentinvention, each the set comprises a single value.

Further preferably, in a memory control method according to the presentinvention, each the set comprises X values where X is an integer greaterthan one.

Further preferably, in a memory control method according to the presentinvention, for the or each the data item, a pointer to an addressallocated to the first set is stored at an address section identifiedwith the data item.

Further preferably, in a memory control method according to the presentinvention, each of the address sections contains sufficient storagespace for the set of values, the local pointer and the far pointer.

Further preferably, in a memory control method according to the presentinvention, each of the address sections contains sufficient storagespace only for the set of values and any pointer which is storable atthe address.

Further preferably, in a memory control method according to the presentinvention, when the memory segment is full, the or each last value iscopied to another memory segment after which the memory segment iserased.

Further preferably, in a memory control method according to the presentinvention, in a cache memory the current value, an address of thecurrent value and the number of the sets of the at least one data itemare stored.

Further preferably, a memory control method according to the presentinvention is a memory control method of storing temporally consecutivevalues of at least one data item in a memory segment of a type in whichstored values cannot be individually overwritten, comprising the stepsof: (a) storing sets of the consecutive values at respective addresssections which are allocated temporally consecutively for the or eachdata item; (b) storing a far pointer to the address of at least one ofthe sets of values at an address section allocated before the addressallocated to the set of values immediately preceding the at least oneset; and (c) storing a local pointer to the address allocated to eachset other than the at least one set at the address section allocated tothe set immediately preceding each other set, said method comprising,starting with an address allocated to the first set: (i) checking theaddress for the presence of a far or local pointer; (ii) if a farpointer is present, performing the step (i) for the address to which thefar pointer points; (iii) if there is a local pointer and no farpointer, performing the step (i) for the address to which the localpointer points; (vi) if there is neither a far pointer nor a localpointer, returning the latest value at the address, thereby achievingthe above-described objectives.

Further preferably, in a memory control method according to the presentinvention, the step (i) comprises checking at least one pointer locationat the address and indicating the presence of a pointer if the at leastone location is in a non-reset state.

Further preferably, in a memory control method according to the presentinvention, the step (iv) comprises storing in a cache memory the latestvalue, a most recently stored far pointer, and the address allocated tothe latest value.

Next, a storage apparatus according to present invention is a storageapparatus for storing temporally consecutively values of at least onedata item, comprising a memory segment of a type in which stored valuescannot be individually overwritten and means for storing sets of theconsecutive values at respective address sections which are allocatedtemporally consecutively for the or each data item, characterised bycomprising means for storing a far pointer to the address of at leastone of the sets of values at an address section allocated before theaddress allocated to the set of values immediately preceding the atleast one set, and means for storing a local pointer to the addressallocated to each set other than the at least one set at the addresssection allocated to the set immediately preceding each other set,thereby achieving the above-described objectives.

Preferably, in a storage apparatus according to the present invention,the memory segment is non-volatile.

Further preferably, in a storage apparatus according to the presentinvention, the memory segment is erasable only as a whole.

Further preferably, in a storage apparatus according to the presentinvention, the memory segment comprises at least part of a flash memory.

Further preferably, in a storage apparatus according to the presentinvention, the at least one set comprises a plurality of sets and theaddress section at which the far pointer of each respective set of theplurality of sets is stored is one which was allocated before the oreach address at which is stored a far pointer to the or each other ofthe plurality of sets to the respective one set.

Further preferably, in a storage apparatus according to the presentinvention, the far pointer storing means comprises means for storing apointer to each [A^(B)(C+1)+(A−B)+K]th set at an address sectionallocated to a [A^(B).C+(A−B)+K]th set, where A is a predeterminedinteger constant greater than 1, B is an integer parameter greater than0, C is an integer parameter which is zero or greater, and K is apredetermined integer constant which is zero or greater.

Further preferably, in a storage apparatus according to the presentinvention, 1≦B≦A and K=0.

Further preferably, in a storage apparatus according to the presentinvention, A=4.

Further preferably, in a storage apparatus according to the presentinvention, each set comprises a single value.

Further preferably, in a storage apparatus according to the presentinvention, each set comprises X values where X is an integer greaterthan 1.

Further preferably, in a storage apparatus according to the presentinvention, means for storing, for the or each data item, a pointer to anaddress allocated to the first set at an address section identified withthe data item is contained.

Further preferably, in a storage apparatus according to the presentinvention, each of the address sections contains sufficient storagespace for the set of values, the local pointer and the far pointer.

Further preferably, in a storage apparatus according to the presentinvention, each of the address sections contains sufficient storagespace only for the set of values and any pointer which is storable atthe address.

Further preferably, in a storage apparatus according to the presentinvention, means for copying the or each last value to another memorysegment when the memory segment is full and means for erasing the memorysegment is contained.

Further preferably, in a storage apparatus according to the presentinvention, a cache memory and means for storing in the cache memory thecurrent value, the address of the current value and number of sets ofthe at least one data item is contained.

Further preferably, in a storage apparatus according to the presentinvention, reading means for: starting with the address allocated to thefirst set, checking the address for the presence of a far or localpointer; if a far pointer is present, checking the address to which thefar pointer points for the presence of a far or local pointer; if thereis a local pointer and no far pointer, checking the address for thepresence of a far or local pointer to which the local pointer points;and, if there is neither a far pointer nor a local pointer, returningthe latest value at the address, is contained.

Further preferably, in a storage apparatus according to the presentinvention, the means for checking for the presence of a far or localpointer comprises means for checking at least one pointer location atthe address section and for indicating the presence of a pointer if theat least one location is in a non-reset state.

Further preferably, in a storage apparatus according to the presentinvention, the means for returning the latest value comprises means forstoring in a cache memory the latest value, the most recently stored farpointer, and the address allocated to the latest value.

Further preferably, in a storage apparatus according to the presentinvention, a storage apparatus according to the present inventioncomprises a computer.

Next, in a storage apparatus according to the present invention,computer program for instructing a computer to perform a processingprocedure of a memory control method as claimed in claim 1, therebyachieving the above-described objectives.

Also, a readable recording medium according to the present inventioncontains a control program as claimed in claim 38, thereby achieving theabove-described objectives.

In view of the above described structures, the invention will be furtherdescribed, by way of example, with reference to the accompanyingdrawings.

In a typical example of the present invention, instead of using a singlelinked chain for updates to a PDI (persistent data item), an acyclicgraph structure is used. Each element has two pointers, instead of one,called L and F (for Local and Far) as well as the data value associatedthereto. Local pointers follow a linear chain, but far pointers can jumpover many intervening elements. The local pointer is initialised as inthe chain method, but the far pointer is left at “FFFF” until the chainis long enough to merit a short-cut. When searching the graph, the ruleis to take the far pointer, if it is not “FFFF”, and otherwise followthe local pointer (and stop when the local pointer is “FFFF” too). Thereare many possible graph shapes which could be chosen and propertieswhich make the choice efficient are as follows:

-   1. The graph must make the search time short, even if the whole    segment is filled with a single PDI's updates;-   2. Searching for the current value should require only a small    amount of extra RAM to hold temporary values;-   3. Update time should be about the same as searching time and use    only a small amount of extra RAM to hold temporary values; and-   4. To save memory capacity, it should be possible to cheaply    calculate information about which nodes L and F subgraphs attach as    nodes are added. It should preferably not be necessary to store this    information in the graph.

The “size” of a graph of updates is defined as the number of times thevalue it represents has been updated. A new PDI therefore has size 0;size 1 when its initial value is set; size 2 after it has been updatedthe first time; and so on. Since the graph always grows by adding onenode at a time, its “shape” (i.e., the topological arrangement of its Land F pointers) for a given size can be predicted independently of thevalues it will store.

For the purpose of illustration, the shape will be considered of a graphwhich has grown to size Nmax (filling a whole segment, say) with justits L and F pointers but without the data values filled in yet. Toreduce searching time to find the most recently added value, the valuesare added in depth-first, L-before-F order. It should be possible todetect efficiently when a sub-graph is considered “full” so that the newvalue can be place in a new sub-graph. To do this, it is necessary tokeep track (at search time) of the available nodes where a sub-graph canbe placed.

-   Address Contents [value, Local, Far]

0000 [date0, FFFF, FFFF] 0000 [date0, 0006, FFFF] 0006 [date1, FFFF,FFFF] 0000 [date0, 0006, FFFF] 0006 [date1, 000C, FFFF] 000C [date2,FFFF, FFFF] 0000 [date0, 0006, FFFF] 0006 [date1, 000C, 0012] 000C[date2, FFFF, FFFF] 0012 [date3, FFFF, FFFF] 0000 [date0, 0006, FFFF]0006 [date1, 000C, 0012] 000C [date2, 0012, FFFF] 0012 [date3, 0018,FFFF] 0018 [date4, FFFF, FFFF]

When garbage collecting, the most recent value is found and copied intothe new segment. The old segment can then be erased.

To find the start of the PDI graphs, an array of pointers is reserved atthe start of each flash memory block or segment. The array is indexed bythe identity of a PDI stored in that block and the content of thatlocation is the required pointer. The table must be updated when it iscopied as the result of a garbage collection.

Such an arrangement has the advantages that:

updating PDI's is fast;

PDI's do not need to have space allocated for them in advance and theupdates proceed to fill available space efficiently. Many PDI's withgreatly differing rates of growth can coexist easily within one segment;

data itself is compact, to reduce total storage requirements;

no RAM is required other than the few bytes of local storage requiredfor the algorithms when they are actually running and a pointer to thenext free memory available within the segment;

some RAM may be used, if available, to cache some pointers and valuesand so speed up access and update times; and

garbage collection removing all update record but the last update recordwhen the segment is full becomes simple.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates the initial part of a PDI structure after a largenumber of updates in the storage apparatus according to the presentinvention;

FIG. 2 illustrates the layout of data within a single flash segment inthe storage apparatus according to the present invention;

FIG. 3 illustrates the structure of PDI nodes in a flash memory in thestorage apparatus according to the present invention;

FIG. 4 illustrates an example of garbage collection in the storageapparatus according to the present invention;

FIG. 5 illustrates an embedded system constituting an embodiment of theinvention;

FIG. 6 is a flow diagram illustrating updating of values in accordancewith an embodiment of the invention;

FIG. 7 illustrates the arrangement of values and pointers in a hybridsystem for managing updates; and

FIG. 8 illustrates a known type of single chain of pointers as describedhereinbefore.

BEST MODE FOR CARRYING OUT THE INVENTION

Hereinafter, an embodiment of a memory control method according to thepresent invention, which is applied to a storage apparatus below, willbe described with reference to accompanying drawings.

FIG. 1 illustrates the initial part of a PDI structure after a largenumber of updates in the storage apparatus according to the presentinvention. In other words, FIG. 1 illustrates a specific example of theinitial part of a structure for a specific PDI whose value has beenupdated many times according to the present invention. Each circle ∘represents a node in the PDI structure and is numbered in the order ofupdating of the PDI (persistent data item). Thus, the initial value isstored at node 0 and nodes 1 to 19 show the first 19 updates.

In FIG. 1, each time a PDI update value is stored by the entry of anupdated value of the PDI, the immediately preceding node is also updatedto contain a local pointer to the address of the new node. Thus, forexample, when the sixth update of PDI has happened, nodes 0 to 6 containthe PDI values in the order of entries and each of nodes 0 to 5 containsa local pointer to the next node. When the seventh PDI updated value isentered, the value is entered at node 7. Although FIG. 1 illustrates alocal pointer from node 6 to node 7, this in fact is not necessary andmay be omitted because a far pointer is entered at node 3 such thatsubsequent searching to find the current value of the PDI will not usethe local pointers at the nodes 4 to 6.

Instead, the searching of the PDI updated values follows the localpointers from the node 0 to node 3 and then the far pointer jumps to thenode 7 so that the nodes 4 to 6, which are intermediate values, arenever checked after the far pointer has been entered at the node 3.Thus, whenever a far pointer has been entered at a node of thestructure, for example, the node previous to the node 7 does not need tocontain a local pointer and memory space may be saved by not allocatingspace at this previous node for a local pointer.

FIG. 2 illustrates the layout of data in a flash memory comprising aplurality of segments 20. The flash segments 20 are erasable as a wholeand the data layout for one of the segments is illustrated. In FIG. 2,this segment contains a fixed segment or “page” header (fixed pageheader) 21 with space pre-allocated for a page identifier and status 22and an ID table 23 of this segment containing an entry for each PDI tobe stored in the segment 20. Each entry is addressable by an identifierassociated with the PDI and contains a pointer to the address containingthe first node of the PDI.

The remainder area of the segment 20 comprises a page data area 24 whichis filled sequentially as updated values of each PDI arrive (entry).When the first value arrives, it is stored at the next available addressin the data area 24 and the address is entered in the Table 23.Subsequent updates are stored at the next available address and previousnodes are updated with local or far pointers as appropriate.

FIG. 1 represents the far pointer destinations by the notional nodenumber but, in practice, the actual memory address within the data area24 is entered as the local or far pointer. Filling up of the data area24 is illustrated by the nodes 25 in a PDI graph as shown in FIG. 2 andthe free space 26 available for storing update contents.

FIG. 3 illustrates a typical PDI node structure in the flash memory. Theaddress of the first value in the Table 23 points to the first node 27in the PDI graph. The first node 27 in the PDI graph has memory spaceallocated for storing a data value 28, a far pointer 29 and a localpointer 30. In this example, a data value 28 is “ABCD” (in hexadecimal),it is assumed that the far pointer 29 has not been entered so that theentry is the erased state “FFFF” (in hexadecimal). However, a subsequentvalue has been entered at the node 31 and the local pointer 30 has beenset to the address of the node 31. The node 31 contains, for example,the data value AE98 (in hexadecimal) but the local and far pointers are“FFFF”, and remain in the erased state.

FIGS. 4( a) through 4(c) illustrate three steps in a garbage collectionoperation according to the present invention. A segment or page 32 hasbeen filled with updated values whereas a next segment 33 is empty andavailable for use as illustrated in FIG. 4( a). In order to allow thePDI updated values to continue to be updated and the segment 32 to beall erased for subsequent use, the latest values of PDI updated valuesare searched and found in the data area of the segment 32 and are copiedinto the segment 33 as shown at FIG. 4( b). The fixed page header of thesegment 33 is formed by entering the page identifier and status and thetable of pointers for the PDIs to the first entries in the page 33.Subsequent updated values are stored in the page 33 as describedhereinbefore and, as shown at (c) in FIG. 4, the page 32 can be erasedand is available for subsequent use.

FIG. 5 illustrates schematically an example of a typical arrangement ofa small computer which may implement the storing and reading of PDIupdate values in the present invention.

This small computer forms a storage apparatus and comprises aninput/output (IO) interface 36 facing outside, working memory in theform of a small random access memory (RAM) 37, a CPU (central processingunit) 35 as a controlling section, a non-volatile memory in the form ofseveral pages of flash memory 38, and an internal or external powersupply 39 which supplies power to these components.

For example, where the storage apparatus is a smart card, the powersupply 39 is external, for example in a card reader, so that power issupplied to the storage apparatus only intermittently. Where the storageapparatus is installed, for example, in a vehicle, the power supply 39may comprise the vehicle power supply and may be made available onlywhen, for example, the vehicle ignition system is switched on. Where thestorage apparatus is intended to be used continuously, such as a remoteinternet router, the power supply 39 is intended to supply powercontinuously and the storage apparatus is capable of retaining itsrecording state in the event of a power failure. This allows the storageapparatus to be re-commissioned relatively easily when power can berestored.

In a specific example illustrating an embodiment, each PDI is allocateda unique 16 bit identifier (ID), giving a theoretical address space ofup to 65536 PDI's. In the simplest embodiment, only a single flashsegment 20 is used to store PDI's, and this restricts the number ofPDI's which can be handled. ID's are allocated sequentially. If amaximum of M PDI's are to be handled, then an array of M pointers(indexed by ID) are allocated in the Table 23 at the beginning of theblock and PDI chains are allocated after this such that the jth elementof the array contains data for the PDI whose ID is equal to j. The jthelement is either “FFFF” (when the PDI has not been allocated yet) oranother value which represents the offset in the block of the start ofthe PDI's graph.

In the graph itself, each node is numbered as shown in FIG. 1 startingfrom the initial value “0” which represents the original value. Eachtime a new element n is added, it is linked from the element n−1, andpossibly from another earlier element, as follows:

-   Each node of the form 256c+0 links to node 256 (c+1)+0.-   Each node of the form 64c+1 links to node 64 (c+1)+1.-   Each node of the form 16c+2 links to node 16 (c+1)+2.-   Each node of the form 4c+3 links to node 4 (c+1)+3.

The numbers (4, 16, 64, 256) have been chosen to produce reasonablesearch times for a 64 KB segment size, but they can be changed asnecessary and are not limited to just four numbers. In this case, it isvery easy (a simple AND and COMPARE operation) to determine if a nodehas a second pointer, because the multiples are powers of two. Eachnumber divides the next larger number, and this makes the schemesimpler, but it is not a necessary simplification.

Nodes are added and pointers updated in accordance with the followingprogram given in C style:

newtype element = record {value v, element* L, element* F} procedureupdatevalue_graph (element* startaddress, value newvalue)  = {  element* p = startaddress;   element* newp = malloc (sizeof(element)); // space for a new element, see below    newp->v = newvalue;// store the new value in the new element    // note: newp.L and newp.Fwill be initially 0xFFFF    element* p4=0xFFFF, p16=0xFFFF, p64=0xFFFF,p256=0xFFFF;   int currentnode = 0;    while (true)     {     if (p->F!= 0xFFFF) // following a far link       {       if (currentnode mod 256= = 0)        {p = p->F; currentnode = currentnode + 256;}       else if(currentnode mod 64 = = 1)         {p = p->F; currentnode =currentnode + 64;}       else if (currentnode mod 16 = = 2)         {p =p->F; currentnode = currentnode + 16;}       else if (currentnode mod 4= = 3)         {p = p->F; currentnode = currentnode +4;}       else        {ERROR!}       }     else if (p->L != 0xFFFF) // following alocal link       {       if (currentnode mod 256 = = 0)        {p256 =p;}       else if (currentnode mod 64 = = 1)         {p64 = p;}       else if (currentnode mod 16 = = 2)          {p16 = p;}       else if (currentnode mod 4 = = 3)          {p4 = p;}        p =p->L;        currentnode = currentnode + 1;        }      else //reached end of chain       {       // (at this point p->v holds thepre-update value)       p->L = newp;       currentnode = currentnode +1;       if (currentnode mod 256 = = 0 AND p256 != 0xFFFF)       {p256->F = newp;}       else if (currentnode mod 64 = = 1 AND p64!= 0xFFFF)        {p64->F = newp;}       else if (currentnode mod 16 = =2 AND p16 != 0xFFFF)        {p16->F = newp;}       else if (currentnodemod 4 = = 3 AND p4 != 0xFFFF)        {p4->F = newp;}       return;      }     } }

The example of a list of updates with shortcuts of lengths 256, 64, 16and 4 is not the only possible choice. In a more general case, therewill be L levels of shortcuts of lengths s(1) . . . , s(L), withs(i)>S(i+1)+1 for all i in {1, . . . , L−1} and s(L)>1.

In an update list U of length n>0, the level 1 shortcuts form a sublistof one or more elements, starting at the first element:U(1), U(1+s(1)), . . . , U(1+k(1)s(1))for some k (1)≧0.

If the level 1 sublist does not reach the end of the list, that is, ifn>1+k(1)s(1), then the level 2 shortcuts form a sublist of one or moreelements, starting one element past the end of the level 1 sublist:U(2+k(1)s(1)), U(2+k(1)s(1)+s(2)), . . . , U(2+k(1)s(1)+k(2)s(2))for some k(2)≧0.

This pattern continues for L levels. At level m, ifn>(m−1)+k(1)s(1)+k(2)s(2)+ . . . +k(m−1)s (m−1), the level m shortcutsform a sublist consisting ofU(m+k(1)s(1)+k(2)s(2)+ . . . +k(m−1)s(m−1)),U(m+k(1)s(1)+k(2)s(2)+ . . . +k(m−1)s(m−1)+s(m))U(m+k(1)s(1)+k(2)s(2)+ . . . +k(m−1)s(m−1)+k(m)s(m))The length of this sublist is k(m)+1.

To make each sublist as long as possible, each k (m) must be the maximumvalue such that:m+k(1)s(1)+ . . . +k(m−1)s(m−1)+k(m)s(m)≦nThis occurs when:

$\begin{matrix}{{k(1)} = {\left( {n - 1} \right)\mspace{11mu}{div}\mspace{14mu} s\mspace{31mu}(1)}} \\\vdots \\{{k(m)} = {\left( {n - m - {{k(1)}{s(1)}} - \ldots - {{k\left( {m - 1} \right)}\mspace{14mu} s\mspace{14mu}\left( {m - 1} \right)}} \right)\mspace{11mu}{div}\mspace{14mu} s\mspace{14mu}(m)}}\end{matrix}$where ‘div’ represents integer division. The remainder from thisdivision,r(m)=(n−m−k(1)s(1)− . . . −k(m−1)s(m−1)) mod s(m)gives the number of elements of U which follow the end of the level msublist.

The lengths of shortcut lists and remainders are bounded byr(m)<=s(m)−1andk(m)<=(s(m−1) div s(m))−1A level m sublist exactly reaches the end of the list if r(m)=0, thatis:(n−m−k(1)s(1)− . . . −k(m−1)s(m−1)) mod s(m)=0

If the shortcut lengths are chosen with each s(i) an exact multiple ofs(i+1), this condition is simplified to(n−m) mod s(m)=0orn mod s(m)=m

The cost C(n) of finding the last element of an update list of length nis the sum of the lengths of the shortcut sublists, plus the length ofthe remainder of the list after the last shortcut. In the worst case,when n≧L and no shortcut exactly reaches element n, a bound for the costis given by:

C(n) = k(1) + 1 + k(2) + 1 + … + k(L) + 1 + r(L) ≤ ((n − 1)div  s(1)) + (s(1)div  s(2)) + … + (s(L − 1)div  s(L)) + s(L) − 1

Choosing values for Lands (i) in this case to optimise C(n) is anengineering trade off which depends on the expected value of n (i.e.,how long the update lists grow). A large value for the largest shortcuts(1) will minimise the first term ((n−1) div s(1)) which will dominatethe cost for large n. A small value for the smallest shortcut s(L) willminimise the number of non-shortcut steps given by the term s(L)−1,which does not depend on n. On the other hand, increasing the ratios(1)/s(L) will increase the sub-or-quotients term:(s(1) div s(2))+ . . . +(s(L−1) div s(L))either by increasing individual ratios (s(i) div s(i+1)) or byincreasing the number of shortcut levels L required to bridge the gap.

FIG. 6 represents operations by the control program for updating PDIvalues according to the present invention in flow diagram form.

In the flow diagram of FIG. 6, p is a pointer to a node in the PDIgraph. The far pointer of p is the far field stored in the PDI structureto which p points. Similarly, the local pointer of p is the local fieldin the PDI structure to which p points. The small variables p₄, p₁₆, p₆₄and p₂₅₆ are bookmarks of past slots for far pointers and are referredto as p_(x); the selection depends on the value of X:4, 16, 64 or 256.The flow chart also contains a subroutine “farlen” with “node” as itsparameter.

In the step S3, a contiguous block of memory is allocated with enoughspace to store the new value and its pointer. The address of the memoryblock is stored in a pointer variable “newp”.

If the storage apparatus has a RAM of a sufficient memory capacitance,the current value, the last chain position and the last chain number maybe stored in RAM for some or all of the PDIs when the storage apparatusstarts operating. This part of the RAM is thus used as a type of cachememory. Although this requires time during the start-up, subsequentlooking up for reading and updating is much faster.

When an update value is read from the flash memory, the most recentpointers may be cached together with the pointer to the current valuebecause this variable is most likely to be the next one to be changed.Storing the far pointer makes updating faster.

Although each node may have space for a single value of its PDI, analternative arrangement is possible whereby any or all of the nodes mayhave space available for storing several updated values. Such anarrangement is illustrated in FIG. 7 where each of the nodes 40 to 42has space for six values together with local and far pointers. In thiscase, instead of allocating each new value to a new node, the values areentered in the spaces in each node until that node is full. The nextvalue is then entered in the first value space of another node and thelocal pointer in the previous node is set to point to the new node. FIG.7 illustrates the situation after 15 updates with the nodes 40 and 41being full, the local pointer of the node 40 pointing to the node 41,the local pointer of the node 41 pointing to the node 42, and the otherpointers in the nodes 40, 41 and 42 being in their reset state. In orderto simplify searching, each such node may have a word with a number ofbits equal to the number of updates which can be stored. Each bitcorresponds to the space for an update and is set when that space isoccupied by an updated value so as to make searching the node easier.

As described above, according to an embodiment of the present invention,a technique can be provided for storing updated values of a PDI (dataitem) in a segment of memory in which stored values cannot beindividually overwritten, such as a flash memory. Each updated value isstored at an address which has space for a far pointer and a localpointer. When a new value is stored, the local pointer of the previousvalue is set to point to the address of the new value. When a chain ofnodes of this type has been established and a further PDI update valueis to be stored, it is entered at a new node and a far pointer at a muchearlier node of the chain is set to point to the new node so that themost recent value can be found without having to follow the localpointers in all of the previous nodes. Thus, PDIs can be updated fast.Therefore, space allocated for the PDI in advance is not required, andthe updates are sequentially proceeded to fill available spaceefficiently. Many PDIs with greatly differing rates of growth cancoexist easily within one segment. Accordingly, total storagerequirements can be reduced so that data itself becomes compact.

INDUSTRIAL APPLICABILITY

In a field of a storage apparatus using a memory control method ofstoring temporally consecutive values to enable reading the latestvalue, PDIs can be updated fast. Furthermore, space allocated for thePDI in advance is not required, and the updates are sequentiallyproceeded to fill available space efficiently. Many PDIs with greatlydiffering rates of growth can coexist easily within one segment.Accordingly, total storage requirements can be reduced so that dataitself becomes compact.

1. A memory control method of storing temporally consecutive values ofat least one data item in a memory segment of a type in which storedvalues cannot be individually overwritten, comprising the steps of: (a)storing sets of the consecutive values at respective address sectionswhich are allocated temporally consecutively for the or each data item;(b) storing far pointers to the addresses of some of the sets of valuesin accordance with a scheme in which each far pointer to each(A^(B)(C+1)+(A−B)+K)th set is stored at an address allocated to a(A^(B)C+(A−B)+K)th set, where A is a predetermined integer constantgreater than one, B is an integer parameter such that 1≦B≦A butexcluding the case where B has a single value, C is an integer parametergreater than 1, and K is a predetermined integer constant greater than1; and (c) storing a local pointer to the address allocated to each setother than the some sets at the address section allocated to the setimmediately preceding each other set, wherein each of the addresssections is allocated when the value or a first value of a new set isreceived for storing and each far and local pointer is stored at itspreviously allocated address section after an address to which it pointshas been allocated to the new set.
 2. A memory control method of storingtemporally consecutive values of at least one data item in a memorysegment of a type in which stored values cannot be individuallyoverwritten, comprising the steps of: (a) storing sets of theconsecutive values at respective address sections which are allocatedtemporally consecutively for the or each data item; (b) storing farpointers to the addresses of some of the sets of values in accordancewith a scheme in which each far pointer to each (A^(B)(C+1)+(A−B)+K)thset is stored at an address allocated to a (A^(B)C+(A−B)+K)th set, whereA is a predetermined integer constant greater than one, B is an integerparameter having all values such that 1≦B≦A, C is an integer parametergreater than 1, and K is a predetermined integer constant greater than1; and (c) storing a local pointer to the address allocated to each setother than the some sets at the address section allocated to the setimmediately preceding each other set, wherein each of the addresssections is allocated when the value or a first value of a new set isreceived for storing and each far and local pointer is stored at itspreviously allocated address section after an address to which it pointshas been allocated to the new set.
 3. A memory control method as claimedin claim 1 or 2, characterised in that the memory segment isnon-volatile.
 4. A memory control method as claimed in claim 1 or 2,characterised in that the memory segment is erasable only as a whole. 5.A memory control method as claimed in claim 4, characterised in that thememory segment comprises at least part of a flash memory.
 6. A memorycontrol method as claimed in claim 1 or 2, characterised in that eachset comprises a single value.
 7. A memory control method as claimed inclaim 1 or 2, characterised in that each set comprises X values where Xis an integer greater than one.
 8. A memory control method as claimed inclaim 1 or 2, characterised by storing, for the or each data item, apointer to an address allocated to the first set at an address sectionidentified with the data item.
 9. A memory control method as claimed inclaim 1 or 2, characterised in that each of the address sectionscontains sufficient storage space for the set of values, the localpointer and the far pointer.
 10. A memory control method as claimed inclaim 1 or 2, characterised in that each of the address sectionscontains sufficient storage space only for the set of values and anypointer which is storable at the address.
 11. A memory control method asclaimed in claim 1 or 2, characterised in that, when the memory segmentis full, the most recently received value of the or each data item iscopied to another memory segment, after which the memory segment iserased.
 12. A memory control method as claimed in claim 1 or 2,characterised by storing in: a cache memory a most recently receivedvalue, an address of the most recently received value and the number ofthe sets of the at least one data item.
 13. A control program forprogramming a computer to perform a memory control method as claimed inclaim 1 or
 2. 14. A readable storage medium containing a control programas claimed in claim
 13. 15. A memory control method as claimed in claim1 or 2, in which each of the far pointers points to an address allocatedafter a plurality of sets for the data item has been stored since theset at the address at which the far point is stored.
 16. A memorycontrol method as, claimed in claim 1 or 2, in which K=0.
 17. A memorycontrol method as claimed in claim 16, in which A=4.
 18. A memorycontrol method of storing temporally consecutive values of at least onedata item in a memory segment of a type in which stored values cannot beindividually overwritten, comprising the steps of: (a) storing sets ofthe consecutive values at respective address sections which areallocated temporally consecutively for the or each data item; (b)storing far pointers to the addresses of some of the sets of values inaccordance with a scheme in which each far pointer to each (A^(B)(C+1)+(A−B)+K)th set is stored at an address allocated to a(A^(B)C+(A−B)+K)th set, where A is a predetermined integer constantgreater than one, B is an integer parameter such that 1≦B≦A butexcluding the case where B has a single value, C is an integer parametergreater than 1, and K is a predetermined integer constant greater than1; and (c) storing a local pointer to the address allocated to each setother than the some sets at the address section allocated to the setimmediately preceding each other set, said method comprising, startingwith the address allocated to the first set: (i) checking the addressfor the presence of a far or local pointer; (ii) if a far pointer ispresent, performing the step (i) for the address to which the farpointer points; (iii) if there is a local pointer and no far pointer,performing the step (i) for the address to which the local pointerpoints; (vi) if there is neither a far pointer nor a local pointer,returning the latest value at the address.
 19. A memory control methodof storing temporally consecutive values of at least one data item in amemory segment of a type in which stored values cannot be individuallyoverwritten, comprising the steps of: (a) storing sets of theconsecutive values at respective address, sections which are allocatedtemporally consecutively for the or each data item; (b) storing farpointers to the addresses of some of the sets of values in accordancewith a scheme in which each far pointer to each (A^(B) (C+1)+(A−B)+K)thset is stored at an address allocated to a (A^(B)C+(A−B)+K)th set, whereA is a predetermined integer constant greater than one, B is an integerparameter having all values such that 1≦B≦A, C is an integer parametergreater than 1, and K is a predetermined integer constant greater than1; and (c) storing a local pointer to the address allocated to each setother than the some sets at the address section allocated to the setimmediately preceding each other set, said method comprising, startingwith the address allocated to the first set: (i) checking the addressfor the presence of a far or local pointer; (ii) if a far pointer ispresent, performing the step (i) for the address to which the farpointer points; (iii) if there is a local pointer and no far pointer,performing the step (i) for the address to which the local pointerpoints; (vi) if there is neither a far pointer nor a local pointer,returning the latest value at the address.
 20. A memory control methodas claimed in claim 18 or 19, characterised in that the step (i)comprises checking at least one pointer location at the address andindicating the presence of a pointer if the at least one location is ina non-reset state.
 21. A memory control method as claimed in claim 18 or19, characterised in that the step (iv) comprises storing in a cachememory the latest value, the most recently stored far pointer, and theaddress allocated to the latest value.
 22. A storage apparatus forstoring temporally consecutively values of at least one data item,comprising a memory segment of a type in which stored values cannot beindividually overwritten and means for storing sets of the consecutivevalues at respective address sections which are allocated temporallyconsecutively for the or each data item, characterised by comprisingmeans for storing far pointers to the addresses of some of the sets ofvalues in accordance with a scheme in which each far pointer to each(A^(B) (C+1)+(A−B)+K)th set is stored at an address allocated to a(A^(B)C+(A−B)+K)th set, where A is a predetermined integer constantgreater than one, B is an integer parameter such that 1≦B≦A butexcluding the case where B has a single value, C is an integer parametergreater than 1, and K is a predetermined integer constant greater than1, and means for storing a local pointer to the address allocated toeach set other than the some sets at the address section allocated tothe set immediately preceding each other set, wherein each of theaddress sections is allocated when the value or a first value of a newset is received for storing and each far and local pointer is stored atits previously allocated address section after an address to which itpoints has been allocated to the new set.
 23. A storage apparatus forstoring temporally consecutively values of at least one data item,comprising a memory segment of a type in which stored values cannot beindividually overwritten and means for storing sets of the consecutivevalues at respective address sections which are allocated temporallyconsecutively for the or each data item, characterised by comprisingmeans for storing far pointers to the addresses of some of the sets ofvalues in accordance with a scheme in which each far pointer to each(A^(B) (C+1)+(A−B)+K)th set is stored at an address allocated to a(A^(B)C+(A−B)+K)th set, where A is a predetermined integer constantgreater than one, B is an integer parameter having all values such that1≦B≦A, C is an integer parameter greater than 1, and K is apredetermined integer constant greater than 1, and means for storing alocal pointer to the address allocated to each set other than the somesets at the address section allocated to the set immediately precedingeach other set, wherein each of the address sections is allocated whenthe value or a first value of a new set is received for storing and eachfar and local pointer is stored at its previously allocated addresssection after an address to which it points has been allocated to thenew set.
 24. A storage apparatus as claimed in claim 22 or 23,characterised in that the memory segment is non-volatile.
 25. A storageapparatus as claimed in claim 22 or 23, characterised in that the memorysegment is erasable only as a whole.
 26. A storage apparatus as claimedin claim 25, characterised in that the memory segment comprises at leastpart of a flash memory.
 27. A storage apparatus as claimed in claim 22or 23, characterised in that each set comprises a single value.
 28. Astorage apparatus as claimed in claim 22 or 23, characterised in thateach set comprises X values where X is an integer greater than
 1. 29. Astorage apparatus as claimed in claim 22 or 23, characterised bycomprising means for storing, for the or each data item, a pointer to anaddress allocated to the first set at an address section identified withthe data item.
 30. A storage apparatus as claimed in claim 22 or 23,characterised in that each of the address sections contains sufficientstorage space for the set of values, the local pointer and the farpointer.
 31. A storage apparatus as claimed in claim 22 or 23,characterised in that each of the address sections contains sufficientstorage space only for the set of values and any pointer which isstorable at the address.
 32. A storage apparatus as claimed in claim 22or 23, characterised by comprising means for copying the most recentlyreceived value of the or each data item to another memory segment whenthe memory segment is full and means for erasing the memory segment. 33.A storage apparatus as claimed in claim 22 or 23, characterised bycomprising a cache memory and means for storing in the cache memory amost recently received value, the address of the current value andnumber of sets of the at least one data item.
 34. A storage apparatus asclaimed in claim 22 or 23, characterised by comprising reading meansfor: starting with the address allocated to the first set, checking theaddress for the presence of a far or local pointer; if a far pointer ispresent, checking the address to which the far pointer points for thepresence of a far or local pointer; if there is a local pointer and nofar pointer, checking the address for the presence of a far or localpointer to which the local pointer points; and, if there is neither afar pointer nor a local pointer, returning the latest value at theaddress.
 35. A storage apparatus as claimed in claim 34, characterisedin that the means for checking for the presence of a far or localpointer comprises means for checking at least one pointer location atthe address section and for indicating the presence of a pointer if theat least one location is in a non-reset state.
 36. A storage apparatusas claimed in claim 34, characterised in that the means for returningthe latest value comprises means for storing in a cache memory thelatest value, the most recently stored far pointer, and the addressallocated to the latest value.
 37. A storage apparatus as claimed inclaim 22 or 23, characterised by comprising a computer.
 38. A storageapparatus as claimed in claim 22 or 23, in which each of the farpointers points to an address allocated after a plurality of sets forthe data item has been stored since the set at the address at which thefar point is stored.
 39. A storage apparatus as claimed in claim 22 or23, in which K=0.
 40. A storage apparatus as claimed in 39, in whichA=4.